package cn.moningxi.controller;

import cn.moningxi.bean.*;
import cn.moningxi.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 前台首面获取渲染数据
 */
@Controller
public class InitController {
    @Autowired
    WebsiteAdverService websiteAdverService;
    @Autowired
    GoodsCategoryService goodsCategoryService;
    @Autowired
    GGoodsBrandService gGoodsBrandService;
    @Autowired
    GArticleService gArticleService;
    @Autowired
    GActivitService gActivitService;

    /**
     * 获取新闻头条列表
     *
     * @param model
     */
    @ModelAttribute
    public void getArticleVoList(Model model) {
        List<GArticle> gArticleList = gArticleService.getHotList();
        model.addAttribute("articleVoList", gArticleList);
    }

    /**
     * 获取热门活动列表
     */
    @ModelAttribute
    public void getIndexActivities(Model model) {
        List<GActivit> gActivitList = gActivitService.getHotList();
        model.addAttribute("indexActivities", gActivitList);
    }

    /**
     * 获取所有分类
     *
     * @param model
     */
    @ModelAttribute
    public void getCategoryList(Model model) {
        List<GoodsCategory> goodsCategoryList = goodsCategoryService.getAll();
        model.addAttribute("categoryList", goodsCategoryList);
        List<GGoodsBrand> gGoodsBrandList = gGoodsBrandService.getHotList();
        model.addAttribute("brandList", gGoodsBrandList);
    }

    /**
     * 首站轮播图
     *
     * @param model
     */
    @ModelAttribute
    public void getCtmAdvers(Model model) {
        List<WebsiteAdver> websiteAdvers = websiteAdverService.getAll();
        model.addAttribute("ctmAdvers", websiteAdvers);
    }

    /**
     * 获取初始化数据
     *
     * @param mv
     * @return
     */
    @RequestMapping("/index/init")
    @ResponseBody
    public ModelAndView init(ModelAndView mv) {
        mv.setViewName("business/home/index");
        return mv;
    }
}
